﻿using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Bll;
using Runda.CMS.Common.Entity;
using Runda.CMS.Common.Utility;
using System.Collections.Generic;
using Telerik.WebControls;
using System;
using System.Collections;
using System.Configuration;

namespace Runda.CMS.Portal.ContractFollowUp
{
    public partial class InstrumentReturnVisitExtra : BasePage
    {
        public Guid MaintainID
        {
            get
            {
                if (hiddenMaintainID.Value == string.Empty) return Guid.Empty;
                else return new Guid(hiddenMaintainID.Value);
            }
            set
            {
                hiddenMaintainID.Value = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["maintainID"] != null)
                {
                    MaintainID = new Guid(Request.QueryString["maintainID"]);
                    List<WsmInstrumentReturnVisitEntity> returnEntitys = new SystemBll().GetAll<WsmInstrumentReturnVisitEntity>("and MaintainID='" + MaintainID.ToString() + "'");
                    if (returnEntitys != null && returnEntitys.Count > 0)
                    {
                        WsmInstrumentReturnVisitEntity entity = returnEntitys[0];                      
                        InstrumentUsingInfo.Text = entity.InstrumentUsingInfo;
                        CustomerInterview.Text = entity.CustomerInterview;
                        ReturnVistResult.Text = entity.ReturnVistResult;
                        RecommendCustomer.Text = entity.RecommendCustomer;                    
                    }
                }
            }
        }
        protected void lnkbtnSaveAndClose_Click(object sender, EventArgs e)
        {
            if (CustomerInterview.Text.Trim().Length + InstrumentUsingInfo.Text.Trim().Length + ReturnVistResult.Text.Trim().Length + RecommendCustomer.Text.Trim().Length < 10)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "save", "alert('客户服务详情描述不能少于10字');", true);
                return;
            }
            SystemBll bll = new SystemBll();
            bll.Delete<WsmInstrumentReturnVisitEntity>(" and MaintainID='" + MaintainID.ToString() + "'");

            WsmInstrumentReturnVisitEntity entity = new WsmInstrumentReturnVisitEntity();
            entity.InstrumentUsingInfo =  InstrumentUsingInfo.Text.Trim();
            entity.CustomerInterview  = CustomerInterview.Text.Trim();
            entity.ReturnVistResult =ReturnVistResult.Text.Trim();
            entity.RecommendCustomer = RecommendCustomer.Text.Trim();                    
            entity.ReturnVisitID = Guid.NewGuid();
            entity.MaintainID = MaintainID;
            bll.InsertOrUpdate(entity);
            ClientScript.RegisterStartupScript(this.GetType(), "save", "alert('保存成功');", true);
        }
    }
}
